package com.api.volunteer.listener;

import com.api.volunteer.model.BaseEntity;
import com.api.volunteer.util.Holder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.persistence.PreUpdate;
import java.util.Date;

/**
 * @author 邹宇杰
 * @email 2901570623@qq.com
 * @date 2022/3/29 22:26
 */
@Component
public class BaseEntityListener {

    @Autowired
    Holder holder;

    @PreUpdate
    public void preUpdate(BaseEntity entity) {

        if (entity != null) {
            entity.setLastUpdateDate(new Date());
            entity.setLastUpdateUserId(holder.getUser().getId());
        }

    }
}

